<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <title>传智健康</title>
    <meta content="传智健康" name="description">
    <meta content="传智健康" name="keywords">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link href="../plugins/elementui/index.css" rel="stylesheet">
    <link href="../plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <!-- 引入组件库 -->
    <script src="../js/jquery.min.js" type="text/javascript"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../js/healthmobile.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表</small></h1>
        <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input @keyup.enter.native="handleFilter" class="filter-item" placeholder="手机号/姓名"
                          style="width: 200px;" v-model="pagination.queryString"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button @click="handleCreate()" class="butT" type="primary">新建</el-button>
            </div>
            <el-table :data="dataList" current-row-key="id" highlight-current-row size="small" stripe>
                <el-table-column align="center" label="预约日期" prop="orderDate"></el-table-column>
                <el-table-column align="center" label="姓名" prop="name"></el-table-column>
                <el-table-column align="center" label="手机号码" prop="phoneNumber"></el-table-column>
                <el-table-column align="center" label="预约类型" prop="orderType"></el-table-column>
                <el-table-column align="center" label="预约状态" prop="orderStatus"></el-table-column>
                <el-table-column align="center" label="操作">
                    <template slot-scope="scope">
                        <el-button @click="handleUpdate(scope.row)" size="mini" type="primary">确认预约</el-button>
                        <el-button @click="handleDelete(scope.row)" size="mini" type="danger">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        :total="pagination.total"
                        @current-change="handleCurrentChange"
                        class="pagiantion"
                        layout="total, prev, pager, next, jumper">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog :visible.sync="dialogFormVisible" title="新增预约">
                    <template>
                        <el-tabs type="card" v-model="activeName">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>

                                        <el-col :span="12">
                                            <el-form-item label="预约时间">

                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="适用性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号码">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" :value="c.id" type="checkbox" v-model="setmealIds">
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div class="dialog-footer" slot="footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button @click="handleAdd()" type="primary">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>

<script>
    export default {
        data() {
            return {
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                value1: '',
            };
        }
    };
</script>


<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 0,
                queryString: null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            setmealIds: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false//控制编辑窗口显示/隐藏


        },
        created() {
            this.findPage();
        },
        methods: {

            //添加
            handleAdd() {
                //获取用户输入的手机号
                var telephone = this.formData.phoneNumber;
                var idCard = this.formData.idCard;
                //使用正则表达式进行手机号合法性校验
                if (!checkTelephone(telephone)) {
                    //校验不通过，返回false
                    this.$message.error("手机号输入错误，请检查后重新输入！");
                    return false;
                }
                if (!checkIdCard(idCard)) {
                    //校验不通过，返回false
                    this.$message.error("身份证号输入错误，请检查后重新输入！");
                    return false;
                }
                //发送ajax请求，需要提交检查组基本信息和勾选的检查项信息
                axios.post("/order/add.do?setmealIds= " + this.setmealIds, this.formData).then((response) => {
                    if (response.data.flag) {
                        this.$message.success(response.data.message);
                        this.findPage();
                    }else {
                        this.$message.error(response.data.message);
                    }
                })
                this.dialogFormVisible=false;


            },
            //分页查询
            findPage() {
                //封装分页查询条件
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };

                //发送ajax请求，进行分页查询
                axios.post("/order/findOrdersPage.do", param).then((res) => {
                    if (res.data.flag) {
                        this.pagination.total = res.data.data.total;
                        this.dataList = res.data.data.rows;
                        this.$message.success(res.data.message);
                    } else {
                        this.$message.error(res.data.message);
                    }

                });


            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.activeName = 'first';
                this.checkitemIds = []
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                //发送ajax请求，查询所有套餐信息，以表格的形式展示到窗口中
                axios.post("/setmeal/findAll.do").then((response) => {
                    if (response.data.flag) {
                        this.tableData = response.data.data;
                    }
                })
            },
            // 确认预约
            handleUpdate(row) {
                var id =row.id;
              axios.post("/order/confirm.do?id="+id).then((response)=>{
                    this.findPage();
              })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 取消预约
            handleDelete(row) {
                var id =row.id;
                axios.post("/order/delete.do?id="+id).then((response)=>{
                    this.findPage();
                })
            }

        }
    })
</script>
</html>
